import * as api from '../api'
export default (state,action)=>{
  state = state || {radioList:[],slider:[]};
  switch(action.type){
    case 'RECOM_INIT':
      return {radioList:action.radioList,slider:action.slider}
    default:
      return state;
  }
}

export const recommend = () => (dispatch) =>{
  setTimeout(()=>{
    fetch(api.RECOMMEND).then(response=>response.json()).then(result=>{
      // console.log(result)
      if(result.errno===0){
        // 整个这个大括号就是action
        dispatch({type:'RECOM_INIT',radioList:result.data.radioList,slider:result.data.slider})
      }
    })
  },100)
}